import { findIndex, uniqueId, cloneDeep } from 'lodash'
import { getCurrentInstance } from 'vue'
import { Messages, confirm } from '@Config/config'
import { message } from 'ant-design-vue'
import { favoriteDelFile, libDownLoadBatch } from '@Config/server/api'
import { useRoute } from 'vue-router'
export const instanceFn = () => {
  let { proxy } = getCurrentInstance()
  let route = useRoute()

  //下载
  let downLoadHandler = async (objs) => {
    objs.map((x) => {
      let _index = findIndex(proxy.tableData.data.source, { id: x.id })
      proxy.tableData.data.source[_index].local_loading = true
    })
    let _r = await libDownLoadBatch({ ids: objs.map((x) => x.id) })

    objs.map((x) => {
      let _index = findIndex(proxy.tableData.data.source, { id: x.id })
      proxy.tableData.data.source[_index].local_loading = false
    })
    if (_r.code == 0) {
      Messages.add(message.success('下载成功'))
      location.href = _r.data
    } else {
      Messages.add(message.error(`下载失败[${_r.msg}]`))
    }
  }
  return {
    // cancelFavorite,
    downLoadHandler,
  }
}
